/**
 * 
 * @authors Riche
 * @date    2016-07-05 10:39:22
 * @version 1.1.0
 */

 var articleID = $.getUrlVar("id");
var forword = encodeURIComponent(window.location.href);
var backUrl = $.getUrlVar("back");

var info=new Vue({
  el:"#app",
  data:{
    attachInfo:[],
    attachList:{    //附件
      isLoading:true,
      pageSize:PAGESIZE,
      pageIndex:1
    }
  },
  compiled:function(){
    var _self = this;
    
    //文档删除
    $(document).on('click','.ooo',function(){
        _self.addShow = false;
        alert({
            close:false,
            text: '是否将其删除？',
            kind: 2,
            okEvent: function(){
                _self.deleteArticle();
            }
        });
    });
  },
  created:function(){
    var dtd = $.Deferred();
    var _self = this;
    var top = $(document).scrollTop();
    $(document).scroll(function () {
      if(top!=$(document).scrollTop()){
          // 上下滚动
          if ($(document).scrollTop() >= $(document).height() - $(window).height()) {
              _self.loadlist();
          }
      }else{
          // 左右滚动
      }
      
    });
    
    _self.loadlist();
  },
  methods:{
    loadlist:function(){
      var _self = this;
      var vModal,target;
      
      var url = 'look_getAnnexListByArticeID';
      var defaults = {
        articleID: articleID,
        pageSize:_self.attachList.pageSize,
        pageIndex:_self.attachList.pageIndex
      } 

      var data = $.extend(defaults,{});

      vModal = _self.attachList;
      target = _self.attachInfo;
        
      if(!vModal || !vModal.isLoading) return;
      data = Common.jsonEncode(data);
      Common.ajaxCall({ url: url, datatype: 'json', type: 'get', data: data}, function (data) {
          if(data.error_code==0 && data.data.length > 0){
              if(vModal.pageIndex==1){
                target.length = 0;
              }
              for(var i = 0; i < data.data.length; i++){
                target.push(data.data[i]);
              }
              
              
          }else{
              vModal.isLoading = false;
          }

          vModal.pageIndex++;
      });
      
    },
    //文档删除
    deleteArticle:function(){
        var _self = this;
        var data = {
            articleID: dataID
        };
        data = Common.jsonEncode(data);
        Common.ajaxCall({ url: 'look_deleteArticle', datatype: 'json', type: 'get', data: data}, function (data) {
            alert(data.msg);
            setTimeout(function(){ _self.back();},1000);
        });
    },
    //文档评分
    addScore:function(){
        var _self = this;
        var data = {
            articleID: dataID,
            score : _self.score
        };
        data = Common.jsonEncode(data);
        Common.ajaxCall({ url: 'look_addScore', datatype: 'json', type: 'get', data: data}, function (data) {
            if(data.error_code==0){
                var obj = data.data[0];
                _self.isScore = 1;
                // var code = obj.code;
                // var pic = code==1?"moneyPig.png":"lebel.png";
                // alert({
                //     text: '<img src="images/'+pic+'"/>',
                //     description: obj.str,
                //     kind: 0
                // });
             //   alert('评分成功');
                //延迟跳转
                //setTimeout(function(){ window.history.go(-1);},1000);
                //window.location.reload();
            }else{
                alert(data.msg);
            }
            _self.score = 0;
        });
    },
    toAttachDetail:function(id){
      window.location.href = "attachDetail.html?articleID=" + articleID +"&annexID="+ id + "&back=" + forword;

    },
    toComment:function(id){
      window.location.href = "comments.html?id=" + id + "&back=" + forword;
    },
    back:function(){
      window.location.href = decodeURIComponent(backUrl);
    }
  },
  watch:{

  }
});



